package com.skywolf.chem.live.controller;


import com.aliyun.oss.ServiceException;
import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.common.sysconfig.response.RespData;
import com.skywolf.chem.live.param.CommentDto;
import com.skywolf.chem.live.param.CommentParam;
import com.skywolf.chem.live.param.CommentQueryDto;
import com.skywolf.chem.live.param.VideoParam;
import com.skywolf.chem.live.service.IVideocommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 视频评论表 前端控制器
 * </p>
 *
 * @author 
 * @since 2020-12-01
 */
@RestController
@RequestMapping("/edu/comment")
@Api(value = "API-评论相关接口", description = "API-评论相关接口")
public class VideocommentController {

    @Autowired
    IVideocommentService commentService;

    @ApiOperation(value = "视频详情-评论列表",notes = "视频详情-评论列表")
    @RequestMapping(value = "/commentList",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<PageVO<CommentDto>> commentList(HttpServletRequest request, @RequestBody @Validated CommentQueryDto queryParam) {
        String uid = request.getHeader("uid");
        PageVO<CommentDto> page = commentService.pageCommentList(queryParam,Long.valueOf(uid));
        return RespData.success(page);
    }


    @ApiOperation(value = "视频详情-添加评论",notes = "视频详情-添加评论")
    @RequestMapping(value = "/addComment",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<String> addComment(HttpServletRequest request, @RequestBody @Validated VideoParam param) {
        String uid = request.getHeader("uid");
        commentService.addComment(param,Long.valueOf(uid));
        return RespData.success("success");
    }

    @ApiOperation(value = "视频详情-视频打分",notes = "视频详情-视频打分")
    @RequestMapping(value = "/scoring",method = {RequestMethod.POST},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<String> scoring(HttpServletRequest request, @RequestBody @Validated CommentParam param) {
        String uid = request.getHeader("uid");
        commentService.scoring(param,Long.valueOf(uid));
        return RespData.success("success");
    }


    @ApiOperation(value = "删除评论",notes = "删除评论")
    @RequestMapping(value = "/delComment",method = {RequestMethod.GET},produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespData<String> delComment(HttpServletRequest request, @RequestParam(value = "id",required = true) Long id) {
        String uid = request.getHeader("uid");
        try{
            commentService.delComment(Long.valueOf(uid),id);
            return RespData.success();
        }catch (ServiceException e){
            return RespData.failResult(e.getErrorMessage());
        }
    }
}
